##geo_regressions_master_iterative.r

##the cities to be iterated through
iterated.cities = unique(data.cities$index.city)
iterated.cities = iterated.cities[iterated.cities!='Jerusalem'] ##don't drop all of jerusalem, only the quarters


##data needed for each
master.use.vars = c('outgroup.dissim.yeshiva','outgroup.yeshiva','demo1.sex','demo1.age','demo1.ethnicity','demo2.left_right','index.city','nonjewish_pcnt','income','college','immigrant','jerusalem')

##master formula, combine with the dependent variable in each script
master.formula = 'outgroup.dissim.yeshiva*outgroup.yeshiva+demo1.sex+demo1.age+demo1.ethnicity+demo2.left_right+income+college+immigrant+nonjewish_pcnt+jerusalem'

master.formula.reduced = 'outgroup.dissim.yeshiva*outgroup.yeshiva'

##names for regression tables
coef.names = c('Intercept', 'Segregation', 'Outgroup Proportion',  'Segregation x Outgroup Proportion', 'Male', 'Age', 'Mixed Ethnicity', 'Other Ethnicity', 'Sephardic Ethnicity', 'Political Ideology','High Income','Low Income','College','Immigrant','Arab Population','Jerusalem')


##loop through cities and remove cases in each one
iterated.cities = iterated.cities[order(iterated.cities)]
for(city in iterated.cities){
  ###source files
  source('scripts/geo_regressions_output_public_iterative.r')
  source('scripts/geo_regressions_output_dictator_iterative.r')
  source('scripts/geo_regressions_output_task_iterative.r')
  
  
  ###############
  ##create omnibus table
  coef.names.omni = c('Intercept', 'Segregation', 'Outgroup Proportion',  'Male', 'Age', 'Mixed Ethnicity', 'Other Ethnicity', 'Sephardic Ethnicity', 'Political Ideology','High Income','Low Income','College','Immigrant','Arab Population','Jerusalem','Segregation x Outgroup Proportion')
  
  outtable = apsrtable(reg.uo.pub,
                       reg.sec.pub,
                       reg.uo.dict,
                       reg.sec.dict,
                       reg.uo.task,
                       reg.sec.task,
                       Sweave = T,
                       coef.names = coef.names.omni,
                       model.names = c('UO','Non UO','UO','Non UO','UO','Non UO'),
                       notes = ''
          )
  city.num = which(iterated.cities == city) + 20
  file.name = paste('output/appendix/Table_A',city.num,'.tex',sep = '')
  
  writeLines(
    outtable,file.name)
    
  }